<template>
	<view class="shopDetail">
		<view class="container" v-if="shopDetail">
			<view class="banner">
				<view class="swiper">
					<swiper circular :autoplay="true" :interval="2000" @change="comCurrent">
						<swiper-item v-for="(item,i) in shopDetail.storeBanners" :key="i">
							<image :src="item"></image>
						</swiper-item>
					</swiper>
					<view class="current">{{current}} / {{shopDetail.storeBanners.length}}</view>
				</view>
				<view class="info">
					<view class="name">{{shopDetail.name}}</view>
					<view class="down">
						<text class="businessHours">营业时间 {{shopDetail.businessHours}}</text>
						<text class="label">{{shopDetail.tablesNum}}张台球桌</text>
						<!-- <text class="label">{{shopDetail.label}}</text> -->
					</view>
				</view>
			</view>

			<view class="addrBox">
				<image src="https://cloudcdn.noitom.com.cn/noitom2/billiard/locationIcon.png"></image>
				<view class="address">{{shopDetail.address}}</view>
				<button @click="openMap">导航</button>
			</view>

			<view class="recharge">
				<view class="top">
					<view class="titleBox">
						<view class="title">会员充值</view>
						<view class="border"></view>
					</view>
					<view class="button" @click="payMore">
						<view class="name">全部档位</view>
						<image src="https://cloudcdn.noitom.com.cn/noitom2/billiard/arrIcon.png"></image>
					</view>
				</view>
				<view class="recommendList">
					<view v-for="(item,i) in shopDetail.recommendList" :key="i" :class="i == 1 ? 'cont big' : 'cont'">
						<image src="https://cloudcdn.noitom.com.cn/noitom2/billiard/recommendIcon.png"
							v-if="item.recommend == 1" class="recommendIcon"></image>
						<view class="presented">充<text>{{item.presented}}</text>元</view>
						<view class="recharge_amount">享受球台消费{{item.rechargeAmount}}折</view>
						<!-- <view class="recharge_amount">充{{item.recharge_amount}}元</view> -->
						<button @click="pay(item.rid)">立即充值</button>
					</view>
				</view>
			</view>

			<view class="coach">
				<view class="top">
					<view class="titleBox">
						<view class="title">私教课</view>
						<view class="border"></view>
					</view>
				</view>
				<scroll-view class="scrollView" scroll-x="true">
					<view v-for="(item,i) in coachList" :key="i" class="cont"
						@click="toCoachDetail(item.cid)">
						<image src="https://cloudcdn.noitom.com.cn/noitom2/billiard/coach_r_icon.png"
							v-if="item.recommend == 1" class="coach_r_icon"></image>
						<image :src="item.imgUrl" class="headPic"></image>
						<view class="name">{{item.name}}</view>
						<view class="level">{{item.level}}教练</view>
						<view class="price"><text class="symbol"></text><text class="num">{{item.price}}</text>/节起
						</view>
					</view>
				</scroll-view>
			</view>

			<view class="league">
				<view class="top">
					<view class="titleBox">
						<view class="title">团体课</view>
						<view class="border"></view>
					</view>
				</view>
				<view class="weekBox">
					<view v-for="(item,i) in shopDetail.leagueList" :key="i"
						:class="activeDay == i ? 'cont active' : 'cont'" @click="changeDay(i)">
						<view class="weedDay">{{i == 0 ? '今天' : item.weekDay}}</view>
						<view class="day">{{item.day}}</view>
					</view>
				</view>

				<view class="activeData">
					<view v-for="(item,i) in activeData.list" :key="i" class="cont">
						<view class="top">
							<view class="course_title">{{item.courseTitle}}</view>
							<view class="num"><text>{{item.cnum}}</text> / {{item.tnum}}人</view>
						</view>
						<view class="label">
							<text v-for="(lItem,lI) in item.label" :key="lI">{{lItem}}</text>
						</view>
						<view class="down">
							<image :src="item.imgUrl" class="imgUrl"></image>
							<text class="coach_name">{{item.coachName}}</text>
							<text class="line"></text>
							<text class="time">{{item.time}}</text>
							<button :disabled="item.status != 0"
								@click="toLeagueDetail(item.id)">{{item.status == 0 ? '预约' : '已预约'}}</button>
						</view>
					</view>
				</view>
			</view>

			<image src="https://cloudcdn.noitom.com.cn/noitom2/billiard/footer_pic.png" class="footer_pic"></image>
		</view>

		<view class="makePhoneBox">
			<button @click="makePhone">
				<uni-icons type="phone-filled" size="16" color="#ffffff"></uni-icons>
				<text>咨询店长</text>
			</button>
		</view>
	</view>
</template>

<script>
	import {
		getStore,
		wechatPay,
		payStatus
	} from "@/api/getData.js";
	export default {
		data() {
			return {
				currentDate: null,
				//店铺详情数据
				shopDetail:null,
				activeDay: 0,
				activeData: null,
				current: 1,
				storeId: null,
				coachList:[]
			}
		},
		onLoad(options) {
			const dd = new Date()
			const y = dd.getFullYear()
			const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期，不足10补0
			const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号，不足10补0
			this.currentDate = y + '-' + m + '-' + d
			// this.activeData = this.shopDetail.leagueList[0]
			this.storeId = options.storeId
			this.getStore()
			this.getCoachList()
		},
		onShow() {},
		methods: {
			openMap() {
				var latitude = this.shopDetail.latitude
				var longitude = this.shopDetail.longitude
				var name = this.shopDetail.address
				wx.openLocation({
					latitude,
					longitude,
					name,
					scale: 18
				})
			},
			pay(rId) {
				this.wechatPay(rId)
			},
			async wechatPay(rId) {
				var _this = this
				const param = {
					orderType: 0,
					id: rId
				}
				const {
					data: res
				} = await wechatPay(param)
				wx.requestPayment({
					timeStamp: res.data.start.timestamp,
					nonceStr: res.data.start.nonceStr,
					package: res.data.pay.packageStr,
					signType: res.data.pay.signType,
					paySign: res.data.pay.paySign,
					success(req) {
						console.log(req)
						_this.payStatus(res.data.paymentId, res.data.start.timestamp, res.data.start.nonceStr,
							res.data.pay.packageStr, res.data.pay.paySign)

					},
					fail(e) {
						console.log(e)
					}
				})
			},
			//支付结果上报
			async payStatus(paymentId, timeStamp, nonceStr, packages, paySign) {
				const param = {
					paymentId: paymentId,
					timeStamp: timeStamp,
					nonceStr: nonceStr,
					packageStr: packages,
					paySign: paySign,
				}
				const {
					data: res
				} = await payStatus(param)
				if (res.data) {
					uni.navigateTo({
						url: "/pages/pay/paymentSuccess?odatetime=" + res.data.odatetime + "&paymentNo=" + res
							.data.paymentNo + "&type=" + res.data.type + "&price=" + res.data.price + ""
					});
				}

			},
			//门店详情
			async getStore() {
				console.log(this.storeId)
				const param = {
					longitude: getApp().globalData.longitude,
					latitude: getApp().globalData.latitude,
					todayDate: this.currentDate,
					storeId: this.storeId
				}
				const {
					data: res
				} = await getStore(param)
				this.shopDetail = res.data
				this.activeData = this.shopDetail.leagueList[0]
			},
			async getCoachList() {
				const param = {
					longitude: getApp().globalData.longitude,
					latitude: getApp().globalData.latitude,
					todayDate: '2023-01-06',
					storeId: this.storeId
				}
				const {
					data: res
				} = await getStore(param)
				this.coachList = res.data.coachList
			},
			//调用手机电话
			makePhone() {
				uni.makePhoneCall({
					phoneNumber: this.shopDetail.phone
				});
			},
			//轮播图索引
			comCurrent(e) {
				this.current = e.detail.current + 1
			},
			//教练等级转换
			conversion(num) {
				switch (num) {
					case 1:
						return '初级教练'
					case 2:
						return '中级教练'
					case 3:
						return '高级教练'

				}
			},
			//选择团课日期
			changeDay(i) {
				this.activeDay = i
				this.activeData = this.shopDetail.leagueList[i]
			},
			//切换门店
			changeShop() {
				uni.navigateTo({
					url: "/pages/shop/shopList"
				});
			},

			//充值列表
			payMore() {
				uni.navigateTo({
					url: "/pages/pay/payList?storeId=" + this.shopDetail.id + ""
				});
			},
			//门店详情
			toDetail(id) {
				uni.navigateTo({
					url: "/pages/shop/shopDetail?storeId=" + id
				});
			},
			//私教详情
			toCoachDetail(cId) {
				uni.navigateTo({
					url: "/pages/course/coachDetail?cId=" + cId
				});
			},
			//团课详情
			toLeagueDetail(lId) {
				uni.navigateTo({
					url: "/pages/course/leagueDetail?lId=" + lId
				});
			}
		}
	}
</script>

<style lang="less">
	.shopDetail {

		.container {
			padding: 32rpx;
		}

		.banner {
			height: 498rpx;
			background: #FFFFFF;
			border-radius: 16rpx;

			.swiper {
				height: 350rpx;
				position: relative;

				swiper {
					height: 100%;
				}

				image {
					display: block;
					width: 100%;
					height: 100%;
				}

				.current {
					width: 75rpx;
					height: 33rpx;
					background: rgba(0, 0, 0, 0.6);
					border-radius: 6rpx;
					right: 14rpx;
					bottom: 19rpx;
					position: absolute;
					font-size: 24rpx;
					color: #FFFFFF;
					line-height: 33rpx;
					text-align: center;
				}
			}

			.info {
				padding: 26rpx 32rpx 0;
				line-height: 1;

				.name {
					font-size: 32rpx;
					font-weight: bold;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.down {
					margin-top: 27rpx;

					.businessHours {
						font-size: 24rpx;
						line-height: 30rpx;
						color: #E60012;
					}

					.label {
						height: 30rpx;
						background: rgba(206, 206, 206, 0.2);
						border-radius: 15rpx;
						padding: 0 18rpx;
						font-size: 20rpx;
						color: #A4A4A4;
						line-height: 30rpx;
						margin-left: 16rpx;
					}
				}
			}
		}


		.addrBox {
			height: 98rpx;
			background: url(https://cloudcdn.noitom.com.cn/noitom2/billiard/address_bg.png) no-repeat;
			background-size: 100% 100%;
			margin-top: 32rpx;
			display: flex;
			align-items: center;

			image {
				width: 18rpx;
				height: 20rpx;
				margin-left: 32rpx;
				margin-right: 16rpx;
			}

			.address {
				width: 373rpx;
				font-size: 24rpx;
			}

			button {
				width: 142rpx;
				height: 58rpx;
				background: linear-gradient(158deg, #E60012, #FF5B63);
				border-radius: 29rpx;
				padding: 0;
				line-height: 58rpx;
				font-size: 24rpx;
				color: #FFFFFF;
				margin-right: 32rpx;
			}
		}

		// 公共title
		.top {
			display: flex;
			justify-content: space-between;

			.titleBox {
				.title {
					font-size: 34rpx;
					position: relative;
					z-index: 10;
				}

				.border {
					width: 62rpx;
					height: 10rpx;
					background: linear-gradient(90deg, #E60012, #FFFFFF);
					border-radius: 5rpx;
					position: relative;
					top: -10rpx;
				}
			}

			.button {
				width: 160rpx;
				height: 46rpx;
				border: 1px solid #A4A4A4;
				border-radius: 23rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				position: relative;
				right: -16rpx;

				.name {
					font-size: 24rpx;
					color: #A4A4A4;
				}

				image {
					width: 23rpx;
					height: 23rpx;
					margin-left: 10rpx;
				}
			}
		}


		.recharge {
			height: 409rpx;
			background: url(https://cloudcdn.noitom.com.cn/noitom2/billiard/topUp_bg.png);
			background-size: 100% 100%;
			margin-top: 32rpx;
			padding: 26rpx 32rpx 32rpx;

			.top {
				.titleBox {
					.title {
						color: #fff;
					}

					.border {
						background: linear-gradient(90deg, #FFBCBF, #FE242A);
					}
				}

				.button {
					border: 1px solid #FFFFFF;

					.name {
						color: #ffffff;
					}

					image {
						width: 12rpx;
						height: 19rpx;
						margin-left: 10rpx;
					}
				}
			}

			.recommendList {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 40rpx;

				.cont {
					width: 190rpx;
					height: 228rpx;
					background: linear-gradient(-40deg, #FFFCE9, #FFD5A0);
					border-radius: 8px;
					text-align: center;
					color: #F4141F;
					line-height: 1;
					position: relative;

					.recommendIcon {
						width: 63rpx;
						height: 63rpx;
						position: absolute;
						top: 0;
						left: 0;
					}

					.presented {
						font-weight: bold;
						font-size: 28rpx;
						margin-top: 44rpx;

						text {
							font-size: 48rpx;
						}
					}

					.recharge_amount {
						font-size: 20rpx;
						margin-top: 15rpx;
					}

					button {
						width: 143rpx;
						height: 43rpx;
						border: 1px solid #F4141F;
						border-radius: 21rpx;
						margin-top: 40rpx;
						font-size: 24px;
						color: #F4141F;
						background: none;
						line-height: 38rpx;
						font-size: 24rpx;
						padding: 0;
					}
				}

				.big {
					width: 212rpx;
					height: 254rpx;

					.presented {
						margin-top: 54rpx;
					}
				}
			}
		}

		.coach {
			background: #fff;
			padding: 30rpx 0 32rpx 32rpx;
			margin-top: 35rpx;
			border-radius: 16rpx;

			.scrollView {
				white-space: nowrap;
				width: 100%;
				margin-top: 32rpx;

				.cont {
					display: inline-block;
					width: 245rpx;
					height: 409rpx;
					background: #FFFFFF;
					border: 1px solid #DFDFDF;
					border-radius: 8rpx;
					margin-right: 16rpx;
					position: relative;

					.coach_r_icon {
						width: 105rpx;
						height: 40rpx;
						position: absolute;
						right: 0;
						top: 0;
					}

					.headPic {
						width: 100%;
						height: 230rpx;
					}

					.name {
						font-size: 32rpx;
						margin-left: 12rpx;
						margin-top: 10rpx;
					}

					.level {
						color: #A4A4A4;
						font-size: 24rpx;
						margin-left: 12rpx;
						margin-top: 6rpx;
					}

					.price {
						font-size: 20rpx;
						color: #A4A4A4;
						margin-left: 12rpx;
						margin-top: 12rpx;

						.symbol {
							color: #E60012;
						}

						.num {
							font-size: 36rpx;
							color: #E60012;
						}
					}
				}
			}
		}

		.league {
			background: #fff;
			padding: 32rpx;
			margin-top: 35rpx;
			border-radius: 16rpx;

			.weekBox {
				display: flex;
				justify-content: space-between;
				margin-top: 35rpx;
				line-height: 1;
				text-align: center;

				.cont {
					.weedDay {
						font-size: 24rpx;
						color: #A4A4A4;
					}

					.day {
						width: 48rpx;
						height: 48rpx;
						background: #ffffff;
						border-radius: 50%;
						font-size: 32rpx;
						font-weight: 500;
						line-height: 48rpx;
						margin: 9rpx auto 0;

					}
				}

				.active {
					.weedDay {
						color: #E60012;
					}

					.day {
						background: #E60012;
						color: #fff;
					}
				}
			}

			.activeData {
				line-height: 1;
				margin-top: 30rpx;

				.cont {
					border-top: 2rpx solid #E2E2E2;
					padding-top: 35rpx;

					.top {
						display: flex;
						justify-content: space-between;

						.course_title {
							width: 441rpx;
							font-size: 32rpx;
							font-weight: 600;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							font-weight: bold;
						}

						.num {
							font-size: 24rpx;
							color: #A4A4A4;

							text {
								font-size: 32rpx;
								color: #E60012;
							}
						}
					}

					.label {
						font-size: 24rpx;
						color: #A4A4A4;
						margin-top: 17rpx;

						text {
							margin-right: 10rpx;
						}
					}

					.down {
						height: 58rpx;
						background: #F7F7F7;
						border-radius: 29rpx;
						display: flex;
						align-items: center;
						margin: 32rpx 0;

						.imgUrl {
							width: 46rpx;
							height: 46rpx;
							margin-left: 6rpx;
							margin-right: 17rpx;
						}

						.coach_name {
							font-size: 24rpx;
						}

						.line {
							display: inline-block;
							width: 2rpx;
							height: 18rpx;
							background: #BDBDBD;
							margin: 0 16rpx;
						}

						.time {
							font-size: 24rpx;
							color: #E60012;
						}

						button {
							width: 142rpx;
							height: 58rpx;
							background: linear-gradient(158deg, #E60012, #FF5B63);
							border-radius: 29rpx;
							margin-right: 0;
							font-size: 24rpx;
							line-height: 58rpx;
							color: #FFFFFF;
						}

						button[disabled]:not([type]) {
							background: #BBBBBB;
						}
					}
				}
			}
		}

		.footer_pic {
			display: block;
			width: 251rpx;
			height: 25rpx;
			margin: 32rpx auto 0;
		}

		.makePhoneBox {
			height: 120rpx;
			background: #FFFFFF;
			overflow: hidden;

			button {
				width: 686rpx;
				height: 98rpx;
				background: #E60012;
				border-radius: 49rpx;
				padding: 0;
				line-height: 98rpx;
				display: flex;
				margin: 11rpx auto;
				justify-content: center;
				align-items: center;
				font-size: 32rpx;
				font-weight: bold;
				color: #FFFFFF;
			}
		}
	}
</style>